package com.example.Less.repository;

import com.example.Less.entity.Project;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface ProjectRepository extends JpaRepository<Project, Integer> {
    @Query("SELECT p FROM Project p WHERE " +
            "(:name IS NULL OR p.name LIKE %:name%) AND " +
            "(:enName IS NULL OR p.enName LIKE %:enName%) AND " +
            "(:addr IS NULL OR p.addr LIKE %:addr%) AND " +
            "(:state IS NULL OR p.state = :state) AND " +
            "(:type IS NULL OR p.type = :type) AND " +
            "(:sort IS NULL OR p.sort = :sort) AND " +
            "(:isDeleted IS NULL OR p.isDeleted = :isDeleted)")
    Page<Project> searchProjects(@Param("name") String name,
                                 @Param("addr") String addr,
                                 @Param("state") String state,
                                 @Param("type") Integer type,
                                 @Param("sort") String sort,
                                 @Param("isDeleted") Integer isDeleted,
                                 @Param("enName") String enName,
                                 Pageable pageable);
}